package com.mnemonic.audio;

import java.awt.Graphics;

import com.mnemonic.GamePage;
import com.mnemonic.Images;

/**
 * 爆炸效果
 * 
 * @author lifeng
 * @date 2021/05/16
 */
public class ExplodeEffect {

    /**
     * 爆炸的地点
     */
    private int x, y;

    /**
     * 执行爆炸的第几步
     */
    private int step = 0;

    /**
     * 雷区的引用
     */
    private GamePage gamePage;

    /**
     * 开启爆炸
     */
    public ExplodeEffect(GamePage gamePage, int x, int y) {
        this.gamePage = gamePage;
        this.x = x;
        this.y = y;
        new ExplodeAudio().start();
    }

    /**
     * 绘制爆炸的效果
     * 
     * @param g
     */
    public void paint(Graphics g) {
        g.drawImage(Images.explodes[step++], x - 30, y - 60, null);
        if (step >= Images.explodes.length) {
            gamePage.removeExplode(this);
        }
    }

    /**
     * 爆炸的音效
     * 
     * @author lifeng
     * @date 2021/05/15
     */
    public class ExplodeAudio extends GameAudio {
        public ExplodeAudio() {
            super("explode.wav");
        }
    }
}
